package com.hjm.project.finance.record.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hjm.framework.aspectj.lang.annotation.Log;
import com.hjm.framework.aspectj.lang.enums.BusinessType;
import com.hjm.project.finance.record.domain.AgentDeductionsRecord;
import com.hjm.project.finance.record.service.IAgentDeductionsRecordService;
import com.hjm.framework.web.controller.BaseController;
import com.hjm.framework.web.domain.AjaxResult;
import com.hjm.common.utils.poi.ExcelUtil;
import javax.annotation.Resource;
import com.hjm.framework.web.page.TableDataInfo;

/**
 * 账户变更记录Controller
 * 
 * @author maker-platform
 * @date 2022-10-28
 */
@Controller
@RequestMapping("/finance/record")
public class AgentDeductionsRecordController extends BaseController {
    private String prefix = "finance/record";

    @Resource
    private IAgentDeductionsRecordService agentDeductionsRecordService;

    @RequiresPermissions("finance:record:view")
    @GetMapping()
    public String record() {
        return prefix + "/record";
    }

    /**
     * 查询账户变更记录列表
     */
    @RequiresPermissions("finance:record:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AgentDeductionsRecord agentDeductionsRecord) {
        startPage();
        List<AgentDeductionsRecord> list = agentDeductionsRecordService.selectAgentDeductionsRecordList(agentDeductionsRecord);
        return getDataTable(list);
    }

    /**
     * 导出账户变更记录列表
     */
    @RequiresPermissions("finance:record:export")
    @Log(title = "账户变更记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AgentDeductionsRecord agentDeductionsRecord) {
        List<AgentDeductionsRecord> list = agentDeductionsRecordService.selectAgentDeductionsRecordList(agentDeductionsRecord);
        ExcelUtil<AgentDeductionsRecord> util = new ExcelUtil<AgentDeductionsRecord>(AgentDeductionsRecord.class);
        return util.exportExcel(list, "record");
    }

    /**
     * 新增账户变更记录
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存账户变更记录
     */
    @RequiresPermissions("finance:record:add")
    @Log(title = "账户变更记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AgentDeductionsRecord agentDeductionsRecord) {
        return toAjax(agentDeductionsRecordService.insertAgentDeductionsRecord(agentDeductionsRecord));
    }

    /**
     * 修改账户变更记录
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
        AgentDeductionsRecord agentDeductionsRecord = agentDeductionsRecordService.selectAgentDeductionsRecordById(id);
        mmap.put("agentDeductionsRecord", agentDeductionsRecord);
        return prefix + "/edit";
    }

    /**
     * 修改保存账户变更记录
     */
    @RequiresPermissions("finance:record:edit")
    @Log(title = "账户变更记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AgentDeductionsRecord agentDeductionsRecord) {
        return toAjax(agentDeductionsRecordService.updateAgentDeductionsRecord(agentDeductionsRecord));
    }

    /**
     * 删除账户变更记录
     */
    @RequiresPermissions("finance:record:remove")
    @Log(title = "账户变更记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(agentDeductionsRecordService.deleteAgentDeductionsRecordByIds(ids));
    }
}
